class Subject{

  constructor(){
    this.stack = []
    this.state = '开心'
  }
  attach(observer){
    this.stack.push(observer);
  }
  setState(newState){
    this.state = newState;
    this.stack.forEach(o=>o.update(newState));
  }
}

class Obeserver {
  constructor(name){
    this.name = name;
  }
  update(newState){
    console.log(this.name+'小宝宝'+newState);
  }
}
let o1 = new Obeserver('爸爸');
let o2 = new Obeserver('妈妈');
let babay = new Subject();
babay.attach(o1);
babay.attach(o2);
babay.setState('111');